//
//  CacheFileManager.m
//  text2
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "CacheFileManager.h"
#import "SDWebImageManager.h"

@implementation CacheFileManager

+ (float)fileSizeAtPath:(NSString *)path{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        long long size = [fileManager attributesOfItemAtPath:path error:nil].fileSize;
        return size/1024.0/1024.0;
    }
    return 0;
}
+ (float)folderSizeAtPath:(NSString *)path{
    NSFileManager *fileManageer = [NSFileManager defaultManager];
    float floderSize = 0;
    if ([fileManageer fileExistsAtPath:path]) {
        NSArray *childerFiles = [fileManageer subpathsAtPath:path];
        for (NSString *fileName in childerFiles) {
            NSString *absolutePath = [path stringByAppendingPathComponent:fileName];
            floderSize += [self fileSizeAtPath:absolutePath];
        }
        return floderSize;
    }
    return 0;
}
+ (void)clearCache:(NSString *)path{
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0 ), ^{
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if ([fileManager fileExistsAtPath:path]) {
            NSArray *childerFiles = [fileManager subpathsAtPath:path];
            for (NSString *fileName in childerFiles) {
                NSString *absolutePath = [path stringByAppendingPathComponent:fileName];
                [fileManager removeItemAtPath:absolutePath error:nil];
            }
        }
        // [[SDImageCache sharedImageCache] clearDisk];
       
    });  
}
+ (NSString *)CachesDirectory
{
    return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
}


@end
